#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import hashlib
import os
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolus.pith.packets.hashbuilder import HashBuilder, HashBuilderError
from unittest import TestCase, TestLoader, TextTestRunner

class TestHashBuilder(TestCase):
    pass
    def test_get_hash1(self):
        data = "somedata"
        
        hash = HashBuilder("md5")
        hash_data = hash.get_hash(data)
        
        hash2 = hashlib.md5()
        hash2.update(data)
        hash_data2 = hash2.hexdigest()
        
        self.assertEqual(hash_data, hash_data2)
        
    def test_get_hash2(self):
        data = "somedata"
        
        hash = HashBuilder("md5")
        hash_data = hash.get_hash(data)
        hash_data2 = hash.get_hash(data)
        
        self.assertEqual(hash_data, hash_data2)
        
    def test_get_missing_file_hash(self):
        hash = HashBuilder("md5")
        missing_file = os.path.join(os.getcwd(), "missing_file")
        
        self.assertRaises(HashBuilderError, hash.get_file_hash, missing_file)

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestHashBuilder)
    TextTestRunner(verbosity=2).run(suite)   

    